Skip to content

Conversation

c410-f3r
Copy link
Contributor

@c410-f3r c410-f3r commented Dec 1, 2024

A year has passed since the creation of #115585 and the feature, as expected, is not moving forward. Let's change that.

This PR proposes changing the arm's syntax from cfg(SOME_CONDITION) => { ... } to SOME_CODITION => {}.

match_cfg! {
   unix => {
        fn foo() { /* unix specific functionality */ }
    }
    target_pointer_width = "32" => {
        fn foo() { /* non-unix, 32-bit functionality */ }
    }
    _ => {
        fn foo() { /* fallback implementation */ }
    }
}

Why? Because after several manual migrations in #116342 it became clear, at least for me, that cfg prefixes are unnecessary, verbose and redundant.

Again, everything is just a proposal to move things forward. If the shown syntax isn't ideal, feel free to close this PR or suggest other alternatives.

@rustbot
Copy link
Collaborator

rustbot commented Dec 1, 2024

r? @davidtwco

rustbot has assigned @davidtwco.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Dec 1, 2024
@c410-f3r c410-f3r changed the title [macro_metavar_expr_concat] Adjust syntax [cfg_match] Adjust syntax Dec 1, 2024
@c410-f3r
Copy link
Contributor Author

c410-f3r commented Dec 1, 2024

@rustbot modify labels: +T-libs-api -T-compiler

@rustbot rustbot added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 1, 2024
@rust-log-analyzer

This comment has been minimized.

@c410-f3r c410-f3r force-pushed the cfg-match-foo-bar-baz branch from d3bc54d to 7087e0d Compare December 1, 2024 23:58
@rust-log-analyzer

This comment has been minimized.

@c410-f3r c410-f3r force-pushed the cfg-match-foo-bar-baz branch from 7087e0d to bf503ec Compare December 2, 2024 00:11
@rust-log-analyzer

This comment has been minimized.

@c410-f3r c410-f3r force-pushed the cfg-match-foo-bar-baz branch from bf503ec to 093de3c Compare December 2, 2024 00:24
@rust-log-analyzer

This comment has been minimized.

@c410-f3r c410-f3r force-pushed the cfg-match-foo-bar-baz branch from 093de3c to 7dedd32 Compare December 2, 2024 00:37
@rust-log-analyzer

This comment has been minimized.

@c410-f3r c410-f3r force-pushed the cfg-match-foo-bar-baz branch from 7dedd32 to 6a107c8 Compare December 2, 2024 01:09
@rust-log-analyzer

This comment has been minimized.

@c410-f3r c410-f3r force-pushed the cfg-match-foo-bar-baz branch from 6a107c8 to 5c363b1 Compare December 2, 2024 01:31
@davidtwco
Copy link
Member

r? libs-api

@rustbot rustbot assigned m-ou-se and unassigned davidtwco Dec 2, 2024
@c410-f3r c410-f3r force-pushed the cfg-match-foo-bar-baz branch from 5c363b1 to c635f0d Compare December 4, 2024 13:18
@c410-f3r
Copy link
Contributor Author

r? libs-api

@rustbot rustbot assigned joshtriplett and unassigned m-ou-se Dec 11, 2024
@joshtriplett
Copy link
Member

This looks great. Let's ship it.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2025
@bors bors merged commit fca1481 into rust-lang:master Jan 16, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 16, 2025
}

#[cfg(not(bootstrap))]
cfg_match! {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't duplicate such large amounts of complicated code next time, it causes headaches when someone is trying to change it (which happened here). Instead it would have been nicer if you had reverted this back to use cfg_if or just plain cfg until the bootstrap compiler had the new cfg_match syntax.

@jieyouxu jieyouxu added the F-cfg_select `#![feature(cfg_select)]` label Aug 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

F-cfg_select `#![feature(cfg_select)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants